package com.sunday.pinxinghui.model.products;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewStub;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sunday.common.adapter.CommenAdapter;
import com.sunday.common.adapter.ViewHolder;
import com.sunday.common.base.BaseActivity;
import com.sunday.common.model.ResultDO;
import com.sunday.common.utils.DeviceUtils;
import com.sunday.common.utils.PixUtils;
import com.sunday.common.utils.SpannalbeStringUtils;
import com.sunday.common.utils.StatusBarUtil;
import com.sunday.common.utils.ToastUtils;
import com.sunday.common.widgets.CircleImageView;
import com.sunday.common.widgets.NoScrollGridView;
import com.sunday.common.widgets.banner.ConvenientBanner;
import com.sunday.common.widgets.banner.holder.ViewHolderCreator;
import com.sunday.pinxinghui.R;
import com.sunday.pinxinghui.adapter.IndexAdHolder;
import com.sunday.pinxinghui.base.BaseApplication;
import com.sunday.pinxinghui.entity.BannerImg;
import com.sunday.pinxinghui.entity.CartConfirm;
import com.sunday.pinxinghui.entity.Comment;
import com.sunday.pinxinghui.entity.Nums;
import com.sunday.pinxinghui.entity.Product;
import com.sunday.pinxinghui.entity.ProductDetail;
import com.sunday.pinxinghui.model.ShowBigImage;
import com.sunday.pinxinghui.model.WebViewActivity;
import com.sunday.pinxinghui.model.mine.MemberCenterActivity;
import com.sunday.pinxinghui.model.order.CartActivity;
import com.sunday.pinxinghui.model.order.OrderConfirmActivity;
import com.sunday.pinxinghui.network.ApiClient;
import com.sunday.pinxinghui.widgets.CountDownView.CountdownView;
import com.sunday.pinxinghui.widgets.GradationScrollView;
import com.sunday.pinxinghui.widgets.MyRatingBar;
import com.sunday.pinxinghui.widgets.ProductWindow;
import com.sunday.pinxinghui.widgets.ShareWindow;

import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import q.rorbin.badgeview.Badge;
import q.rorbin.badgeview.QBadgeView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import static com.sunday.pinxinghui.network.ApiClient.CUSTOMER_URL;


/**
 * Created by 刘涛 on 2017/8/15.
 */

public class ProductDetailActivity extends BaseActivity {


    @Bind(R.id.title_text)
    TextView titleText;
    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.title_image)
    ImageView titleImage;
    @Bind(R.id.title_layout)
    RelativeLayout titleLayout;
    @Bind(R.id.banner)
    ConvenientBanner banner;
    @Bind(R.id.view_stub)
    ViewStub viewStub;
    @Bind(R.id.product_title)
    TextView productTitle;
    @Bind(R.id.view)
    View view;
    @Bind(R.id.btn_collect)
    TextView btnCollect;
    @Bind(R.id.product_desc)
    TextView productDesc;
    @Bind(R.id.price_market)
    TextView priceMarket;
    @Bind(R.id.price_now)
    TextView priceNow;
    @Bind(R.id.price_vip)
    TextView priceVip;
    @Bind(R.id.price_layout)
    RelativeLayout priceLayout;
    @Bind(R.id.product_sale_num)
    TextView productSaleNum;
    @Bind(R.id.product_addr)
    TextView productAddr;
    @Bind(R.id.product_store_num)
    TextView productStoreNum;
    @Bind(R.id.extra_layout)
    RelativeLayout extraLayout;
    @Bind(R.id.join_vip_layout)
    RelativeLayout joinVipLayout;
    @Bind(R.id.select_spec)
    TextView selectSpec;
    @Bind(R.id.comment_num)
    TextView commentNum;
    @Bind(R.id.comment_user_logo)
    CircleImageView commentUserLogo;
    @Bind(R.id.comment_user_name)
    TextView commentUserName;
    @Bind(R.id.rating_bar)
    MyRatingBar ratingBar;
    @Bind(R.id.comment_user_time)
    TextView commentUserTime;
    @Bind(R.id.comment_user_content)
    TextView commentUserContent;
    @Bind(R.id.comment_user_imgs)
    NoScrollGridView commentUserImgs;
    @Bind(R.id.btn_more_comment)
    TextView btnMoreComment;
    @Bind(R.id.comment_layout)
    RelativeLayout commentLayout;
    @Bind(R.id.web_view)
    WebView webView;
    @Bind(R.id.recommend_list_view)
    NoScrollGridView recommendListView;
    @Bind(R.id.scrollview)
    GradationScrollView scrollView;
    @Bind(R.id.img_service)
    TextView imgService;
    @Bind(R.id.img_cart)
    TextView imgCart;
    @Bind(R.id.add_cart)
    TextView addCart;
    @Bind(R.id.buy_now)
    TextView buyNow;
    @Bind(R.id.bottom_layout)
    LinearLayout bottomLayout;
    @Bind(R.id.group_desc)
    TextView groupDesc;
    @Bind(R.id.good_comment_num)
    TextView goodCommentNum;


    private int type;//0:正常 1：秒杀 2：限时抢购
    private long productId;
    private long memberId;
    private ProductDetail productDetail;
    private ProductWindow productWindow;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product_detail);
        ButterKnife.bind(this);
        titleText.setText("商品详情");
        productId = getIntent().getLongExtra("productId", 0);
        memberId = BaseApplication.getInstance().getMember().getId();
        initView();
        getProductDetai();
    }

    private void initView() {
        scrollView.setScrollViewListener(new GradationScrollView.ScrollViewListener() {
            @Override
            public void onScrollChanged(GradationScrollView scrollView, int x, int y, int oldx, int oldy) {
                if (y < DeviceUtils.getDisplay(mContext).widthPixels - PixUtils.dip2px(mContext, 48) - StatusBarUtil.getStatusBarHeight(mContext)) {
                    titleLayout.setBackgroundColor(Color.parseColor("#00000000"));
                    titleText.setVisibility(View.GONE);
                    back.setImageResource(R.mipmap.arrow_left);
                } else {
                    titleLayout.setBackgroundColor(Color.parseColor("#ffffff"));
                    titleText.setVisibility(View.VISIBLE);
                    titleText.setTextColor(Color.parseColor("#333333"));
                    back.setImageResource(R.mipmap.arrow_left);
                }
            }
        });
    }

    private void getProductDetai() {
        showLoadingDialog(0);
        Call<ResultDO<ProductDetail>> call = ApiClient.getApiAdapter().getProductDetail(productId, memberId);
        call.enqueue(new Callback<ResultDO<ProductDetail>>() {
            @Override
            public void onResponse(Call<ResultDO<ProductDetail>> call, Response<ResultDO<ProductDetail>> response) {
                dissMissDialog();
                if (isFinish || response.body() == null) {
                    return;
                }
                if (response.body().getCode() == 0) {
                    productDetail = response.body().getResult();
                    updateView(productDetail);
                   getCartNums();
                } else {
                    ToastUtils.showToast(mContext, response.body().getMessage());
                }

            }

            @Override
            public void onFailure(Call<ResultDO<ProductDetail>> call, Throwable t) {
                dissMissDialog();
                ToastUtils.showToast(mContext, R.string.network_error);
            }
        });
    }


    Badge badge;

    private void getCartNums() {
        Call<ResultDO<Nums>> call = ApiClient.getApiAdapter().getCartsNum(BaseApplication.getInstance().getMember().getId());
        call.enqueue(new Callback<ResultDO<Nums>>() {
            @Override
            public void onResponse(Call<ResultDO<Nums>> call, Response<ResultDO<Nums>> response) {
                if (isFinish || response.body() == null) {
                    return;
                }
                if (response.body().getCode() == 0) {
                    if (badge == null) {
                        badge = new QBadgeView(mContext).bindTarget(imgCart).setBadgeNumber(response.body().getResult().getNum());
                    } else {
                        badge.setBadgeNumber(response.body().getResult().getNum());
                    }
                    badge.setShowShadow(false);
                    badge.setBadgeBackground(ContextCompat.getDrawable(mContext, R.color.main_color), true);
                    badge.setBadgeGravity(Gravity.END | Gravity.TOP);
                    badge.setGravityOffset(10, 0, true);
                    badge.setBadgeTextSize(9, true);
                }
            }

            @Override
            public void onFailure(Call<ResultDO<Nums>> call, Throwable t) {
                ToastUtils.showToast(mContext, R.string.network_error);
            }
        });
    }


    @SuppressLint("DefaultLocale")
    private void updateView(ProductDetail productDetail) {
        if (productDetail == null) {
            return;
        }
        final List<BannerImg> bannerImgs = new ArrayList<>();
        if (productDetail.getImages() != null && productDetail.getImages().size() > 0) {
            bannerImgs.addAll(productDetail.getImages());
        }
        banner.getLayoutParams().width = DeviceUtils.getDisplay(mContext).widthPixels;
        banner.getLayoutParams().height = DeviceUtils.getDisplay(mContext).widthPixels * 118 / 100;
        //banner.startTurning(3000);
        banner.setFocusable(true);
        banner.setFocusableInTouchMode(true);
        banner.requestFocus();
        final IndexAdHolder indexAdHolder = new IndexAdHolder();
        banner.setPages(new ViewHolderCreator<IndexAdHolder>() {
            @Override
            public IndexAdHolder createHolder() {
                return indexAdHolder;
            }
        }, bannerImgs)
                .setPageIndicator(new int[]{R.drawable.ic_page_indicator, R.drawable.ic_page_indicator_focused});
        banner.notifyDataSetChanged();

        indexAdHolder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BannerImg item = (BannerImg) v.getTag();
                if (item.getType() == 2) {
                    intent = new Intent(mContext, ShowVideoActivity.class);
                    intent.putExtra("url", item.getUrl());
                    startActivity(intent);
                }
            }
        });


        productTitle.setText(productDetail.getProductName());
        productDesc.setText(productDetail.getSummary());
        btnCollect.setSelected(productDetail.getIsCollect() == 1);
        btnCollect.setText(productDetail.getIsCollect() == 1 ? "已收藏" : "收藏");

        switch (productDetail.getType()) {
            case 1:
                //普通商品
                priceLayout.setVisibility(View.VISIBLE);
                priceMarket.setText(String.format("市价¥%s", productDetail.getCostPrice().setScale(2, RoundingMode.HALF_UP)));
                priceMarket.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
                priceNow.setText(String.format("¥%s", productDetail.getSalePrice().setScale(2, RoundingMode.HALF_UP)));
                priceVip.setText(String.format("会员价:¥%s", productDetail.getVipPrice().setScale(2, RoundingMode.HALF_UP)));

                break;
            case 2:
                //秒杀产品
                priceLayout.setVisibility(View.GONE);
                viewStub.setLayoutResource(R.layout.layout_pro_miaosha);
                viewStub.inflate();
                TextView priceNow = (TextView) findViewById(R.id.product_qg_price_now);
                priceNow.setText(String.format("¥%s", productDetail.getSalePrice().setScale(2, RoundingMode.HALF_UP)));
                TextView priceMarket = (TextView) findViewById(R.id.product_qg_price_market);
                priceMarket.setText(String.format("¥%s", productDetail.getCostPrice().setScale(2, RoundingMode.HALF_UP)));
                priceMarket.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
                TextView salePercent = (TextView) findViewById(R.id.txt_qg_percent);
                salePercent.setText("已抢购" + productDetail.getPercent() + "%");
                ProgressBar progressBar = (ProgressBar) findViewById(R.id.product_qg_progress_bar);
                progressBar.setMax(100);
                progressBar.setProgress(productDetail.getPercent());
                break;
            case 3:
                //限时购商品
                priceLayout.setVisibility(View.GONE);
                viewStub.setLayoutResource(R.layout.layout_pro_qianggou);
                viewStub.inflate();
                TextView priceNow1 = (TextView) findViewById(R.id.product_ms_price_now);
                priceNow1.setText(String.format("¥%s", productDetail.getSalePrice().setScale(2, RoundingMode.HALF_UP)));
                TextView priceMarket1 = (TextView) findViewById(R.id.product_ms_price_market);
                priceMarket1.setText(String.format("¥%s", productDetail.getCostPrice().setScale(2, RoundingMode.HALF_UP)));
                priceMarket1.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
                CountdownView mCvCountdownView = (CountdownView) findViewById(R.id.countdown_view);
                TextView mCvCountdownTextView = (TextView) findViewById(R.id.countdown_txt);
                if (productDetail.getStatus() == 1) {
                    mCvCountdownTextView.setText("距离本场开始：");
                    mCvCountdownView.start(productDetail.getTime() * 1000); // Millisecond
                } else if (productDetail.getStatus() == 2) {
                    mCvCountdownTextView.setText("距离本场结束：");
                    mCvCountdownView.start(productDetail.getTime() * 1000); // Millisecond
                } else {
                    mCvCountdownTextView.setText("本场已结束：");
                    mCvCountdownView.start(0); // Millisecond
                }


                break;
        }
        productSaleNum.setText("已售" + productDetail.getSaleCount());
        productAddr.setText("产地：" + productDetail.getArea());
        if (productDetail.getStore() == 0) {
            productStoreNum.setText("已售罄");
            productStoreNum.setTextColor(ContextCompat.getColor(mContext, R.color.main_color));
        } else {
            productStoreNum.setText("库存" + productDetail.getStore());
        }

        WebSettings webSettings = webView.getSettings();
        //webSettings.setJavaScriptEnabled(true);
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setSupportZoom(true);
        webView.setWebChromeClient(new WebChromeClient());
        webView.loadUrl(productDetail.getDetailUrl());

        commentNum.setText(SpannalbeStringUtils.setTextColor("用户评价", ContextCompat.getColor(mContext, R.color._333)));
        commentNum.append(SpannalbeStringUtils.setTextColor(String.format("(%d)", productDetail.getCommentCount()),
                ContextCompat.getColor(mContext, R.color._999)));
        if (productDetail.getCommentCount() == 0) {
            btnMoreComment.setText("暂无评价");
            commentLayout.setVisibility(View.GONE);

        } else {
            commentLayout.setVisibility(View.VISIBLE);
            goodCommentNum.setText(SpannalbeStringUtils.setTextColor("好评率：", ContextCompat.getColor(mContext, R.color._333)));
            goodCommentNum.append(SpannalbeStringUtils.setTextColor(String.format("%d%%", productDetail.getGoodCommet()),
                    ContextCompat.getColor(mContext, R.color._999)));
            if (productDetail.getComments() != null && productDetail.getComments().size() > 0) {
                final Comment comment = productDetail.getComments().get(0);
                Glide.with(mContext)
                        .load(comment.getMemberLogo())
                        .error(R.mipmap.ic_default)
                        .into(commentUserLogo);
                commentUserName.setText(comment.getMemberName());
                commentUserTime.setText(comment.getTime());
                commentUserContent.setText(comment.getContent());
                if (comment.getImages() != null && comment.getImages().size() > 0) {
                    commentUserImgs.setAdapter(new CommenAdapter<String>(mContext, comment.getImages(), R.layout.list_comment_img_item) {
                        @Override
                        public void convert(ViewHolder helper, String item, int position) {
                            ImageView imgView = helper.getView(R.id.comment_img);
                            Glide.with(mContext)
                                    .load(item)
                                    .error(R.mipmap.ic_default)
                                    .into(imgView);
                        }
                    });
                    commentUserImgs.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                            Intent intent = new Intent(mContext, ShowBigImage.class);
                            intent.putStringArrayListExtra("data", (ArrayList<String>) comment.getImages());
                            intent.putExtra("index", position);
                            mContext.startActivity(intent);
                        }
                    });
                }

                ratingBar.setRating((int) comment.getScore(), R.drawable.rating_bar, false, 15);
            }
        }

        if (productDetail.getProducts() != null && productDetail.getProducts().size() > 0) {
            recommendListView.setAdapter(new CommenAdapter<Product>(mContext, productDetail.getProducts(), R.layout.layout_recommend_item) {
                @Override
                public void convert(ViewHolder helper, final Product item, int position) {
                    ImageView imgView = helper.getView(R.id.product_img);
                    ImageView flagImg = helper.getView(R.id.flag_img);
                    imgView.getLayoutParams().width = DeviceUtils.getDisplay(mContext).widthPixels / 3 - 10;
                    imgView.getLayoutParams().height = DeviceUtils.getDisplay(mContext).widthPixels / 3 - 10;
                    TextView recProPriceNow = helper.getView(R.id.product_price);
                    recProPriceNow.setText(String.format("¥%s", item.getPrice().setScale(2, RoundingMode.HALF_UP)));
                    TextView recProPriceVip = helper.getView(R.id.product_old_price);
                    Glide.with(mContext)
                            .load(item.getImage())
                            .error(R.mipmap.ic_default)
                            .into(imgView);
                    switch (item.getType()) {
                        case 1:
                            //普通商品
                            flagImg.setVisibility(View.GONE);
                            recProPriceVip.setText(String.format("会员价:¥%s", item.getPrice().setScale(2, RoundingMode.HALF_UP)));
                            break;
                        case 2:
                            //秒杀产品
                            flagImg.setVisibility(View.VISIBLE);
                            flagImg.setImageResource(R.mipmap.miaosha);
                            recProPriceVip.setText(String.format("秒杀价:¥%s", item.getPrice().setScale(2, RoundingMode.HALF_UP)));
                            break;
                        case 3:
                            //限时购商品
                            flagImg.setVisibility(View.VISIBLE);
                            flagImg.setImageResource(R.mipmap.qianggou);
                            recProPriceVip.setText(String.format("抢购价:¥%s", item.getPrice().setScale(2, RoundingMode.HALF_UP)));
                            break;
                    }
                    TextView recProTitle = helper.getView(R.id.product_title);
                    recProTitle.setText(item.getProductName());
                    helper.getView(R.id.product_layout).setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            intent = new Intent(mContext, ProductDetailActivity.class);
                            intent.putExtra("productId", item.getProductId());
                            startActivity(intent);
                        }
                    });
                }
            });
        }


        //是否是组合产品
        groupDesc.setText(productDetail.getIsGroup() == 1 ? "组合产品" : "为你推荐");

    }

    @OnClick({R.id.title_image, R.id.btn_collect, R.id.select_spec, R.id.btn_more_comment, R.id.img_service, R.id.img_cart, R.id.add_cart, R.id.buy_now,
            R.id.join_vip_layout})
    void onClick(View v) {
        switch (v.getId()) {
            case R.id.title_image:
                ShareWindow shareWindow = new ShareWindow(mContext, null, null,
                        productDetail.getImage(), null, null, true);
                shareWindow.showPopupWindow(titleImage);
                break;
            case R.id.btn_collect:
                doCollect();

                break;
            case R.id.select_spec:
                if (productDetail == null) {
                    return;
                }
                if (productWindow == null) {
                    productWindow = new ProductWindow(mContext, productDetail, click);
                }

                productWindow.show(selectSpec, 0, productDetail.getType());
                break;
            case R.id.btn_more_comment:
                if (productDetail.getCommentCount() > 0) {
                    intent = new Intent(mContext, CommentListActivity.class);
                    intent.putExtra("productId", productId);
                    startActivity(intent);
                }
                break;
            case R.id.img_service:
                intent = new Intent(mContext, WebViewActivity.class);
                intent.putExtra("title", "客服");
                intent.putExtra("url", CUSTOMER_URL);
                startActivity(intent);
                break;
            case R.id.img_cart:
                intent = new Intent(mContext, CartActivity.class);
                startActivity(intent);
                break;
            case R.id.add_cart:
                if (productDetail == null) {
                    return;
                }
                if (productDetail.getType() == 3 && productDetail.getStatus() == 1) {
                    ToastUtils.showToast(mContext, "活动暂未开始");
                    return;
                }
                if (productWindow == null) {
                    productWindow = new ProductWindow(mContext, productDetail, click);
                }

                productWindow.show(selectSpec, 1, productDetail.getType());
                break;
            case R.id.buy_now:
                if (productDetail == null) {
                    return;
                }
                if (productDetail.getType() == 3 && productDetail.getStatus() == 1) {
                    ToastUtils.showToast(mContext, "活动暂未开始");
                    return;
                }
                if (productWindow == null) {
                    productWindow = new ProductWindow(mContext, productDetail, click);
                }

                productWindow.show(selectSpec, 2, productDetail.getType());
                break;
            case R.id.join_vip_layout:
                intent = new Intent(mContext, MemberCenterActivity.class);
                startActivity(intent);
                break;
        }
    }

    private void doCollect() {
        Call<ResultDO> call = ApiClient.getApiAdapter().doCollect(productId, memberId);
        call.enqueue(new Callback<ResultDO>() {
            @Override
            public void onResponse(Call<ResultDO> call, Response<ResultDO> response) {
                if (response.body() == null || isFinish) {
                    return;
                }
                if (response.body().getCode() == 0) {
                    btnCollect.setSelected(!btnCollect.isSelected());
                    btnCollect.setText(btnCollect.isSelected() ? "已收藏" : "收藏");
                } else {
                    ToastUtils.showToast(mContext, response.body().getMessage());
                }

            }

            @Override
            public void onFailure(Call<ResultDO> call, Throwable t) {

            }
        });
    }


    private ProductWindow.Click click = new ProductWindow.Click() {
        @Override
        public void click(Integer normalId, int num, int type) {
            switch (type) {
                //加入购物车
                case 1:
                    addCart(normalId, num);
                    break;
                //立即购买
                case 2:
                    buyNow(normalId, num);
                    break;
            }
        }
    };

    private void addCart(Integer normalId, int num) {
        Call<ResultDO> call = ApiClient.getApiAdapter().addCart(productId, memberId, normalId, num);
        call.enqueue(new Callback<ResultDO>() {
            @Override
            public void onResponse(Call<ResultDO> call, Response<ResultDO> response) {
                if (response.body() == null || isFinish) {
                    return;
                }
                if (response.body().getCode() == 0) {
                    productWindow.dismiss();
                    ToastUtils.showToast(mContext, "成功加入购物车");
                    getCartNums();
                } else {
                    ToastUtils.showToast(mContext, response.body().getMessage());
                }

            }

            @Override
            public void onFailure(Call<ResultDO> call, Throwable t) {
                ToastUtils.showToast(mContext, R.string.network_error);
            }
        });
    }

    private void buyNow(final Integer normalId, int num) {
        showLoadingDialog(0);
        Call<ResultDO<CartConfirm>> call = ApiClient.getApiAdapter().buyNowConfirmOrder(productId, num, normalId, memberId, null);
        call.enqueue(new Callback<ResultDO<CartConfirm>>() {
            @Override
            public void onResponse(Call<ResultDO<CartConfirm>> call, Response<ResultDO<CartConfirm>> response) {
                dissMissDialog();
                if (isFinish || response.body() == null) {
                    return;
                }
                if (response.body().getCode() == 0) {
                    Intent intent = new Intent(mContext, OrderConfirmActivity.class);
                    intent.putExtra("orderConfirm", response.body().getResult());
                    intent.putExtra("normalId", normalId);
                    intent.putExtra("isFromBuyNow", true);
                    intent.putExtra("productId", productId);
                    mContext.startActivity(intent);
                } else {
                    ToastUtils.showToast(mContext, response.body().getMessage());
                }
            }

            @Override
            public void onFailure(Call<ResultDO<CartConfirm>> call, Throwable t) {
                dissMissDialog();
                ToastUtils.showToast(mContext, R.string.network_error);
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
       // getCartNums();
    }
}
